﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using WebMvc.Utils.ConfigurationInfo;

namespace WebMvc.Controllers
{
    public class A02ConfigurationController : Controller
    {
        private readonly IConfiguration _configuration;
        private readonly ConnectionStringOptions _connectionStringOptions;
        private readonly ConnectionStringOptions _options;

        public A02ConfigurationController(IOptionsMonitor<ConnectionStringOptions> optionsMonitor, IOptions<ConnectionStringOptions> options, IConfiguration configuration)
        {
            _configuration = configuration;
            _connectionStringOptions = optionsMonitor.CurrentValue;
            _options = options.Value;
        }

        public IActionResult Index([FromServices] IOptionsMonitor<ConnectionStringOptions> optionsMonitor, [FromServices] IOptions<ConnectionStringOptions> options)
        {
            Console.WriteLine($"Id: {_configuration["Id"]}");
            Console.WriteLine($"Name: {_configuration["Name"]}");
            Console.WriteLine($"TeachInfo.Id: {_configuration["TeachInfo:Id"]}");
            Console.WriteLine($"TeachInfo.Name: {_configuration["TeachInfo:Name"]}");
            Console.WriteLine($"ConnectionStrings.WriteConnection: {_configuration["ConnectionStrings:WriteConnection"]}");
            Console.WriteLine($"ConnectionStrings.ReadConnectionList0: {_configuration["ConnectionStrings:ReadConnectionList:0"]}");
            Console.WriteLine($"ConnectionStrings.ReadConnectionList1: {_configuration["ConnectionStrings:ReadConnectionList:1"]}");
            Console.WriteLine($"ConnectionStrings.ReadConnectionList2: {_configuration["ConnectionStrings:ReadConnectionList:2"]}");

            return View();
        }
    }
}
